package br.edu.unilasalle.simon_api.domain;

import java.io.Serializable;

import javax.persistence.MappedSuperclass;

@SuppressWarnings("serial")
@MappedSuperclass
public abstract class BaseEntity<ID extends Serializable> implements Serializable {

	public abstract ID getId();
	
	public abstract void setId(ID id);

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = this.getClass().hashCode();
		result = prime * result + ((getId() == null) ? super.hashCode() : getId().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof BaseEntity<?>)) {
			return false;
		}
		BaseEntity<?> other = (BaseEntity<?>) obj;
		if (getId() == null) {
			if (other.getId() != null) {
				return false;
			} else {
				return super.equals(obj);
			}
		} else if (!getId().equals(other.getId())) {
			return false;
		}
		return true;
	}
	
	@Override
	public String toString() {
		return this.getClass().getName() + "[id=" + getId() + "]";
	}
	
}
